// 对wx.request 进行封装
// 主要针对Promsion 
import { resolve } from "url";

function request(url,method = "GET",data = {},header={}){
    return new Promise((resolve,reject) => {
        wx.request({
            url,
            method,
            data,
            header,
            success:res => {
                resolve(res);
            }
        });
    });
}

// request.baseURL = "https://www.zhengzhicheng.cn/api/public/v1/";
// request.baseURL = "https://itjustfun.cn/api/public/v1/";
request.baseURL = "https://autumnfish.cn/wx/api/public/v1/";
request.get = function(url,data){
    return request(request.baseURL + url,"GET",data);
},
// 封装 post 请求方法
request.post = function(url, data) {
    return request(request.baseURL + url, "POST", data);
  };
  
  // 封装带 token 的请求方法
  request.auth = function(url, data) {
    return request(request.baseURL + url, "POST", data, header);
  };

// 导出 request 函数
export default request;